package com.vcredit.creditcat.service.product.shared;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.vcredit.creditcat.service.product.CommonProductApplyNewService;
import com.vcredit.creditcat.service.product.IProductApplyNewService;
import com.vcredit.creditcat.service.product.IProductApplyResultService;


public abstract class ProductApplyServiceAdaptor implements ApplicationContextAware{
	
	public static final String BEANNAME_PREFIX = "product_apply_service_";
	
	public static final String RESULT_BEANNAME_PREFIX = "product_apply_service_result";
	
	private ApplicationContext applicationContext;
	
	public void setApplicationContext(ApplicationContext applicationContext) {
		this.applicationContext = applicationContext;
	}
	
	
	/**
	 * 获取各产品对接service实现类
	 * @author zhaoqi01
	 * @param productId
	 * @return
	 */
	public IProductApplyNewService getProductApplyServiceImpl(Long productId) {
		try {
			return (IProductApplyNewService) applicationContext.getBean(BEANNAME_PREFIX + productId);
		} catch (BeansException e) {
		}
		return (IProductApplyNewService) applicationContext.getBean(CommonProductApplyNewService.class);
	}
	
	/**
	 * 获取各产品授信结果实现类
	 * @param productId
	 * @return
	 */	 
	public IProductApplyResultService getProductApplyResultServiceImpl(Long productId) {
		return (IProductApplyResultService) applicationContext.getBean(RESULT_BEANNAME_PREFIX + productId);
	}
	
}
